<template>
  <div class="app-container clearfix">  
    <div class="filter-container">
      <el-form ref="filterForm" :model="filterForm" :inline="true" label-position="left" label-width="100px">
        <el-form-item label="订单编号" prop="orderID">
          <el-input v-model="filterForm.orderID" clearable placeholder="订单编号" style="width: 200px;" class="filter-item" @keyup.enter.native="handleFilter" />
        </el-form-item>
        <el-form-item label="下单时间" prop="orderTimes">
          <el-date-picker 
          clearable
            v-model="filterForm.orderTimes"
            type="daterange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="支付时间" prop="payTime">
          <el-date-picker 
          clearable
            v-model="filterForm.payTime"
            type="daterange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="支付状态" prop="orderStatus">          
            <el-radio-group v-model="filterForm.orderStatus">
              <el-radio-button label="0">全部</el-radio-button>
              <el-radio-button label="1">已支付</el-radio-button>
              <el-radio-button label="2">未支付</el-radio-button>
            </el-radio-group>
        </el-form-item>
      </el-form>
      <el-button @click="handleFilter()">搜索</el-button>
    </div>
      <el-table
      :data="list"
      border
      style="width: 100%">
      <el-table-column
      type="selection"
      width="55">
    </el-table-column>
      <el-table-column
        label="产品">
        <template slot-scope="{row}">
          <div class="product-list" v-if="row.product.length == 1" v-for="(product,index) in row.product" :key="index">
            <div>
              <img :src="product.productLogo" width="100" height="100" />
            </div>
            <div>{{ product.productName }}</div>
          </div>
          <div class="product-box" v-else-if="row.product.length > 1" >
            <div class="product-box-item" v-for="(product,index) in row.product" :key="index">              
              <div>
                <img :src="product.productLogo" width="100" height="100" />
              </div>
              <div class="product-box-item-title">{{ product.productName }}</div>
            </div>
          </div>
          <div v-else>没有产品</div>
        </template>
      </el-table-column>
      <el-table-column
        label="付款金额" width="140">
        <template slot-scope="{row}">
          <div>￥{{ row.payAmount }}</div>
        </template>
      </el-table-column>
      <el-table-column
        label="支付方式" width="140">
        <template slot-scope="{row}">
          <div>{{ row.settlement.settlementName }}</div>
        </template>
      </el-table-column>
      <el-table-column
        label="优惠金额" width="140">
        <template slot-scope="{row}">
          <div>￥{{ row.discountAmount }}</div>
        </template>
      </el-table-column>
      <el-table-column
        label="客户" width="200">
        <template slot-scope="{row}">
          <div>{{ row.client.fullname }}</div>
        </template>
      </el-table-column>
      <el-table-column
        label="订单状态"
        width="100">
        <template slot-scope="{row}">
          <el-tag v-if="row.orderStatus == 1" type="danger" effect="dark">待支付</el-tag>
          <el-tag v-else-if="row.orderStatus == 2" type="warning" effect="dark">已取消</el-tag>
          <el-tag v-else-if="row.orderStatus == 3" type="info" effect="dark">到期取消</el-tag>
          <el-tag v-else-if="row.orderStatus == 4" effect="dark">已支付</el-tag>
          <el-tag v-else-if="row.orderStatus == 5" effect="dark">已删除</el-tag>
          <el-tag v-else effect="dark">未定义</el-tag>
        </template>
      </el-table-column>
      <el-table-column
        label="下单时间"
        width="160">
        <template slot-scope="{row}">
          <span>{{ row.orderTime }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        width="320">
        <template slot-scope="{row}">
          <el-button @click="handleUpdate(row.ID)">备注</el-button>
          <el-button @click="handleButtonRemove(row.ID)" type="danger">删除</el-button>
          <el-button @click="handleRefundButton(row)">申请退款</el-button>
        </template>
      </el-table-column>
      </el-table>
    <pagination v-show="total>0" :total="total" :page.sync="filterForm.page" :limit.sync="filterForm.size" @pagination="getList" />
  </div>
</template>

<script>
import waves from '@/directive/waves' // waves directive
import Pagination from '@/components/Pagination' // secondary package based on el-pagination
import {getOrderList, removeOrder} from '@/api/sale/order'



export default {
  name: 'financeDashboard',
  components: { Pagination },
  directives: { waves },
  filters: {
  },
  data() {
    return {
      
      socket:"",
      tableKey: 0,
      list: null,
      windowHeight:"600",
      total: 0,
      listLoading: false,
      documentationList:[],
      connected:"loading",
      timer:null,
      filterForm: {
        page: 1,
        size: 10,
        flashsaleStatus:0,
        keyword: undefined
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    getList:function(){
      let _this = this;
      getOrderList(_this.filterForm).then((response) => {
        console.log("getList",response)
          if (response.code === 200) {
            this.list = response.data.list
            this.total = response.data.total
          } else {
            _this.$message({
              message: response.msg,
              type: 'error'
            })
          }
      })
    },
    handleButtonRemove:function(orderID){
      let _this = this;
      removeOrder({
        "orderID":orderID
      }).then((response) => {
        console.log("getList",response)
          if (response.code === 200) {
            _this.getList()
          } else {
            _this.$message({
              message: response.msg,
              type: 'error'
            })
          }
      })
    },
    handleFilter() {
      this.filterForm.page = 1
      this.getList()
    },
    sortChange:function(){

    }
  }
}
</script>
<style>
.filter { float: left; width: 160px; padding: 20px; min-height: 600px; }
.article { float: left; width: 800px; }
.article-item { width: 800px; height: 200px; margin-right: 25px; }
.article-item-text { float: left; width:600px; }
.article-item-icon { float: right; width:200px; height:150px; padding-left: 50px; }
.article-item-icon img { width:100%; height:100%; border-radius: 10px; }
.product-list { display: flex; }
.product-list img { border-radius: 10px; margin-right: 15px; }

.product-box { display: flex;}
.product-box-item { margin-right: 10px;}
.product-box-item img { border-radius: 10px; }
.product-box-item-title { width: 100px; height: 30px; line-height: 30px; overflow: hidden; }
</style>